package net.huashitong.Project.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import jodd.util.StringUtil;
import net.huashitong.Project.entity.ProjectCollection;
import net.huashitong.Project.filter.ProjectCollectionFilter;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public class ProjectCollectionDao extends StringDao<ProjectCollection> {

    public List<ProjectCollection> queryByFilter(ProjectCollectionFilter filter){
        GenericQuery query = createQuery("obj");
        //收藏标志为1，表示确认收藏
        query.append(" and obj.collectFlag=:collectFlag").setParam("collectFlag", "1");
        return query.listResult(filter);
    }


    public List<ProjectCollection> queryByProjectIdAndUser(String projectId, String userId){
        GenericQuery query = createQuery("obj");
        //收藏标志为1，表示确认收藏
        query.append(" and obj.collectFlag=:collectFlag").setParam("collectFlag", "1");

        if (StringUtil.isNotBlank(projectId)){
            query.append(" and obj.projectId=:projectId").setParam("projectId", projectId);

        }
        if (StringUtil.isNotBlank(userId)){
            query.append(" and obj.collectUser=:collectUser").setParam("collectUser", userId);

        }
        return query.listResult();
    }

    public List<ProjectCollection> queryAll(){
        GenericQuery query = createQuery("obj");
        //收藏标志为1，表示确认收藏
        query.append(" and obj.collectFlag=:collectFlag").setParam("collectFlag", "1");
        return query.listResult();
    }

}
